package git.soulbgm.common.base;

import com.baomidou.mybatisplus.core.enums.SqlMethod;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;

/**
 * IServiceExpand 实现类（ 泛型：M 是 mapper 对象，T 是实体 ）
 *
 * @author SoulBGM
 * @date 2022/05/07 00:23
 */
public class ServiceExpandImpl<M extends BaseMapperExpand<T>, T> extends ServiceImpl<M, T> implements IServiceExpand<T> {

    @Override
    public boolean upsert(T entity) {
        return SqlHelper.retBool(getBaseMapper().upsert(entity));
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean upsertList(Collection<T> entityList) {
        int result = getBaseMapper().upsertList(entityList);
        return result == entityList.size();
    }
}
